#include<iostream>
#include<vector>
#include<stack>
#include<string>
#include<cstring>
using namespace std;

class Solution {
public:
	string decodeString(string s) {
		stack<string> sstk;
		stack<int> nstk;
		string result;
		string symbol = "";
		int num = 0;
		for (int i = 0; i < s.length(); i++) {
			if (isdigit(s[i])) {
				num = int(s[i] - '0') + num * 10;
			}
			else if (isalpha(s[i]))
				symbol += s[i];
			else if (s[i] == '[') {
				sstk.push(symbol);
				nstk.push(num);
				symbol = "";
				num = 0;
			}
			else {
				int rep = nstk.top();
				for (int i = 0; i < rep; i++)
					sstk.top() = sstk.top() + symbol;
				symbol = sstk.top();
				sstk.pop();
				nstk.pop();
			}
		}
		result = result + symbol;
		return result;
	}
};


void main() {
	Solution so;
	string s = "3[a2[c]]";
	string ans=so.decodeString(s);
	cout << ans << endl;
}

